package com.zzyl.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;


@Service
public class NursingProjectServiceImpl implements NursingProjectService {
    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    @Override
    public PageResponse<NursingProjectVo> queryPage(String name, Integer pageNum, Integer pageSize, Integer status) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingProject> page = nursingProjectMapper.queryBy(name, status);
        PageResponse<NursingProjectVo> nursingProjectVoPageResponse = PageResponse.of(page, NursingProjectVo.class);
        return nursingProjectVoPageResponse;
    }

    @Override
    public void add(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = new NursingProject();
        BeanUtils.copyProperties(nursingProjectDto, nursingProject);
        nursingProject.setCreateTime(LocalDateTime.now());
        nursingProject.setUpdateTime(LocalDateTime.now());
        nursingProject.setCreateBy(1L);
        nursingProject.setUpdateBy(1L);
        nursingProjectMapper.add(nursingProject);

    }

    @Override
    public NursingProjectVo getById(Long id) {
        NursingProject nursingProject = nursingProjectMapper.selectByPrimaryKey(id);
        NursingProjectVo nursingProjectVo = new NursingProjectVo();
        BeanUtils.copyProperties(nursingProject, nursingProjectVo);
        return nursingProjectVo;

    }

    @Override
    public void update(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = new NursingProject();
        BeanUtils.copyProperties(nursingProjectDto, nursingProject);
        nursingProject.setUpdateTime(LocalDateTime.now());
        nursingProject.setUpdateBy(1L);
        nursingProjectMapper.upDate(nursingProject);
    }

    @Override
    public void delete(Long id) {
        nursingProjectMapper.delete(id);
    }

    @Override
    public List<NursingProjectVo> getAll() {
        List<NursingProjectVo> nursingProjectVos = nursingProjectMapper.getAll();
        return nursingProjectVos;
    }

    @Override
    public void enableOrDisable(Long id, Integer status) {
        nursingProjectMapper.enableOrDisable(id, status);
    }


}
